package com.luojing.springcloud.config.orderdelay;

import com.luojing.springcloud.service.OrderService;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @author luojing
 * @create 2018/10/29 9:40 AM
 **/
@Component
public class TaskRunner implements CommandLineRunner {
  @Autowired
  OrderService orderService;

  @Autowired
  private OrderDelayQueue orderDelayQueue;

  @Override
  public void run(String... args) throws Exception {
    Thread t1 = new Thread(new OrderDelayTask(orderService));
    Thread t2 = new Thread(new OrderDelayTask(orderService));

    t1.start();
    t2.start();

    //模拟生成订单
    int id = 0;
    while (true){
      orderDelayQueue.add(new OrderDelayMsg(id,"1","2", TimeUnit.NANOSECONDS.convert(10,TimeUnit.SECONDS)));
      Thread.sleep(1000L);
      id++;
    }
  }
}
